const ratelimit=require('koa-ratelimit');
const redis=new require('ioredis')({db:2});

const emailBasedRateLimit = ratelimit({
    db: redis,
    duration: 60000,
    max: 2,//duration时间内允许请求的最大次数
    id: ctx=>{
        return ctx.request.body.email;
    }
});
const ipBasedRateLimit = ratelimit({
    db: redis,
    duration: 60000,
    max: 2,
    id: ctx=>{
        return ctx.request.ip;
    }
});

module.exports={
    emailBasedRateLimit,
    ipBasedRateLimit
};